
#include "Mouse.h"

#include <Riccsson/Xna/Framework/RGame.h>

using namespace Riccsson::System;
using namespace Riccsson::Xna::Framework::Input;

PROP3GET_STATIC_INIT(Mouse, IntPtr, WindowHandle);

PROP3_GET_CPP(Mouse, IntPtr, WindowHandle)
{
	throw NotImplementedException();
}

MouseState Mouse::GetState()
{
#if Windows
	POINT p;
	if (GetCursorPos(&p))
	{
		RECT rect;
		GetWindowRect(g_hWnd, &rect);
		
		p.x -= rect.left;
		p.y -= rect.top;
		int wheel = 0;
		ButtonState leftButton( GetAsyncKeyState(VK_LBUTTON) != 0 ? ButtonState::Pressed : ButtonState::Released );
		ButtonState middleButton( GetAsyncKeyState(VK_MBUTTON) != 0 ? ButtonState::Pressed : ButtonState::Released );
		ButtonState rightButton( GetAsyncKeyState(VK_RBUTTON) != 0 ? ButtonState::Pressed : ButtonState::Released );
		ButtonState xButton1( GetAsyncKeyState(VK_XBUTTON1) != 0 ? ButtonState::Pressed : ButtonState::Released );
		ButtonState xButton2( GetAsyncKeyState(VK_XBUTTON2) != 0 ? ButtonState::Pressed : ButtonState::Released );

		return MouseState(p.x, p.y, wheel, leftButton, middleButton, rightButton, xButton1, xButton2);
	}
#else
	throw NotImplementedException();
#endif
	
	return MouseState(0, 0, 0, ButtonState::Released, ButtonState::Released, ButtonState::Released, ButtonState::Released, ButtonState::Released);
}

void Mouse::SetPosition(int x, int y)
{
#if Windows
	SetCursorPos(x, y);
#else
	throw NotImplementedException();
#endif
}